/*****************************************************
*                                                                          
*               COPYRIGHT (c) 2015-2017 Hargic Corporation              
*                         All Rights Reserved                              
*                                                                          
* The source code contained or described herein and all documents          
* related to the source code ("Material") are owned by Hargic         
* Corporation or its licensors.  Title to the Material remains             
* with Hargic Corporation or its suppliers and licensors.               
*                                                                          
* The Material is protected by worldwide copyright and trade secret        
* laws and treaty provisions. No part of the Material may be used,         
* copied, reproduced, modified, published, uploaded, posted, transmitted,  
* distributed, or disclosed in any way except in accordance with the       
* applicable license agreement.                                            
*                                                                          
* No license under any patent, copyright, trade secret or other            
* intellectual property right is granted to or conferred upon you by       
* disclosure or delivery of the Materials, either expressly, by            
* implication, inducement, estoppel, except in accordance with the         
* applicable license agreement.                                            
*                                                                          
* Unless otherwise agreed by Hargic in writing, you may not remove or   
* alter this notice or any other notice embedded in Materials by Hargic 
* or Hargic's suppliers or licensors in any way.                        
*                                                                          
** Author: ted.huang
** Date: 2018-03-03
*
*****************************************************/

/***** Include files ********************************/
#include "msg_handler.h"

/***** Defines **************************************/

/***** Define structure *****************************/

/***** Define constant ******************************/

/***** Define global ********************************/

/***** Define Prototype of functions ****************/

/**
 * @brief
 * @param  None
 * @retval remaining data length
 */
void message_process(uint8_t *data, uint16_t len)
{
    msg_header_t *head;

    head = (msg_header_t *)data;

    switch(head->cmd)
    {
        case MSG_TYPE_CMD_LED_RESP: led_resp_handler(data + MSG_HEADER_SIZEOF, head->len); break;
    }
}

static void led_resp_handler(uint8_t *body, uint16_t len)
{
    msg_type_led_t *led = (msg_type_led_t *)body;

    if (len != sizeof(msg_type_led_t))
        return ;

    // TODO: should check sub device, if the response status is right
    led->did = led->did;
    led->status = led->status;
}

int16_t led_send_req(msg_type_led_t *led)
{
    return message_send(MSG_TYPE_CMD_LED_REQ, (uint8_t *)led, sizeof(msg_type_led_t));
}

/* End of file */



